package WrittenTest;

import java.util.Arrays;

public class test19 {
    // 扑克牌问题，任意5张牌判断能否组成顺子 (0代表任意数)
    // 算法原理：双指针，排序
    public static void main(String[] args) {
        int[] nums = {0, 3, 2, 6, 4};
        int count = 0, n = nums.length, sum = 0, k = 0;
        int[] arr = new int[5];
        // 排序
        Arrays.sort(nums);
        for (int i = 0; i < n; ) {
            int j = i + 1;
            while (j < n) {
                if (nums[j] - nums[j - 1] == 1) {
                    j++;
                }
                else if (nums[j] - nums[j - 1] > 1 && nums[j - 1] != 0) {
                    arr[k] = nums[j] - nums[j - 1] - 1;
                    k++;
                    j++;
                }
                // 小优化
                else if (nums[j] - nums[j - 1] == 0 && nums[j] != 0) {
                    System.out.println(false);
                    return;
                } else {
                    break;
                }
            }
            i = j;
        }
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
            if (nums[i] == 0) {
                count++;
            }
        }
        System.out.println(sum <= count);
    }
}
